package ip4util

import "net"

// IP2Int IP地址转整数
func IP2Int(ip net.IP) (n int) {
	for i, p := range ip.To4() {
		n += int(p) << ((3 - i) * 8)
	}
	return
}

// Int2IP 整数转IP地址
func Int2IP(n int) net.IP {
	if n > 0xffffffff {
		return net.IPv4zero
	}
	ip4 := net.IPv4(byte(n&0xff000000>>24), byte(n&0x00ff0000>>16), byte(n&0x0000ff00>>8), byte(n&0x000000ff))
	return ip4.To4()
}
